import axios from 'services/axiosConfig.js'
import { UserApi } from 'services/apiConfig.js'
import localStorageService from 'store/localStorageService.js'

class UserService {
  isLogin () {
    return localStorageService.getNowUser() !== null
  }
  login (loginUser) {
    return axios({
      method: UserApi.login.method,
      url: UserApi.login.url + '?User.username=' + loginUser.username + '&User.password=' + loginUser.password
    })
  }
  register (registerUser) {
    return axios({
      method: UserApi.register.method,
      url: UserApi.register.url,
      data: registerUser
    })
  }
  getUserByUsername(username) {
    return axios({
      method: UserApi.getUserByUsername.method,
      url: UserApi.getUserByUsername.url + '?User.username=' + username
    })
  }
  getUserById(userId) {
    return axios({
      method: UserApi.getUserById.method,
      url: UserApi.getUserById.url + '?User.id=' + userId
    })
  }
  getAllUsers() {
    return axios({
      method: UserApi.getAllUsers.method,
      url: UserApi.getAllUsers.url + '?User.role=2'
    })
  }
}

export default new UserService()
